Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests for the chat (context files) #1930

Merged
merged 9 commits into from
Aug 9, 2024

Conversation

mkondratek
Copy link
Contributor

@mkondratek mkondratek commented Jul 22, 2024

This is a follow up PR for #1928.

TODO

  • cody commit update

Test plan

  1. Green CI

@mkondratek mkondratek self-assigned this Jul 22, 2024
@mkondratek mkondratek marked this pull request as draft July 22, 2024 11:09
@mkondratek mkondratek changed the title Fix context file items presentation Add integration tests for Chat (context files) Jul 22, 2024
@mkondratek mkondratek changed the title Add integration tests for Chat (context files) Add integration tests for the chat (context files) Jul 22, 2024
@mkondratek mkondratek marked this pull request as ready for review July 23, 2024 12:07
@@ -54,7 +54,12 @@ class MessagesPanel(private val project: Project, private val chatSession: ChatS

@RequiresEdt
fun removeBlinkingCursor() {
components.find { it is BlinkingCursorComponent }?.let { remove(it) }
components
.find { it is BlinkingCursorComponent }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use as? - you won't need to cast it twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

val repos = agent.server.getRepoIds(param).get()
result.complete(repos?.repos ?: emptyList())
} catch (e: Exception) {
result.complete(emptyList())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can replace it with assert with exception message logged out?
This way if it will fail we will also know why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


val session = runInEdtAndGet {
val mySession = AgentChatSession.createNew(project)
mySession.sendWebviewMessage(
Copy link
Contributor

@pkukielka pkukielka Jul 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we couldn't do it using mySession.getPanel().contextView.updateFromSavedState (or updateFromAgent)?
It would test even more components this way.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

import com.intellij.util.ui.UIUtil
import java.awt.Dimension
import java.awt.Font
import java.awt.Graphics
import javax.swing.JPanel
import javax.swing.Timer

class BlinkingCursorComponent private constructor() : JPanel() {
class BlinkingCursorComponent : JPanel(), Disposable {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test execution threw this error:

Not disposed javax.swing.Timer: Timer (listeners: [com.sourcegraph.cody.chat.ui.BlinkingCursorComponent$$Lambda$1647/0x0000000801020c40@5a35a08]) (delayed for 482ms); queue:TimerQueue (javax.swing.Timer@5d0d7a2b)
junit.framework.AssertionFailedError: Not disposed javax.swing.Timer: Timer (listeners: [com.sourcegraph.cody.chat.ui.BlinkingCursorComponent$$Lambda$1647/0x0000000801020c40@5a35a08]) (delayed for 482ms); queue:TimerQueue (javax.swing.Timer@5d0d7a2b)
	at com.intellij.testFramework.TestApplicationManagerKt.checkJavaSwingTimersAreDisposed(TestApplicationManager.kt:355)
	at com.intellij.testFramework.TestApplicationManagerKt.tearDownProjectAndApp(TestApplicationManager.kt:207)
	at com.intellij.testFramework.fixtures.impl.LightIdeaTestFixtureImpl.lambda$tearDown$3(LightIdeaTestFixtureImpl.java:79)
	at com.intellij.testFramework.RunAllKt.doRun(runAll.kt:50)
	at com.intellij.testFramework.RunAllKt.access$doRun(runAll.kt:1)
	at com.intellij.testFramework.RunAll.run(runAll.kt:17)
	at com.intellij.testFramework.fixtures.impl.LightIdeaTestFixtureImpl.tearDown(LightIdeaTestFixtureImpl.java:105)
	at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.lambda$tearDown$33(CodeInsightTestFixtureImpl.java:1326)
	at com.intellij.testFramework.EdtTestUtil.lambda$runInEdtAndWait$1(EdtTestUtil.java:40)
	at com.intellij.openapi.application.TransactionGuardImpl.runWithWritingAllowed(TransactionGuardImpl.java:215)
	at com.intellij.openapi.application.TransactionGuardImpl.access$100(TransactionGuardImpl.java:22)
	at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:197)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
	at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:511)
	at com.intellij.openapi.application.impl.LaterInvocator$1.run(LaterInvocator.java:96)
	at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:69)
	at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:112)
	at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:42)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:776)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:727)
	at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:746)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:898)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.java:746)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$6(IdeEventQueue.java:439)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:803)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$7(IdeEventQueue.java:438)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:119)
	at com.intellij.ide.IdeEventQueue.performActivity(IdeEventQueue.java:604)
	at com.intellij.ide.IdeEventQueue.lambda$dispatchEvent$8(IdeEventQueue.java:436)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:873)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:484)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

@odisseus odisseus self-requested a review July 24, 2024 00:01
components
.firstNotNullOfOrNull { it as? BlinkingCursorComponent }
?.let {
it.dispose()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Jetbrains documentation says that Disposable.dispose() should never be called directly. However, it turns out that we do this a lot in our source code, and I don't expect this PR to rectify all those occurrences.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point - I fixed it in this place. I will review the other places later.

Comment on lines 51 to 57
await.atMost(15, TimeUnit.SECONDS) until
{
val messages = session.messages
messages.size == 2 &&
!messages[0].contextFiles.isNullOrEmpty() &&
!messages[1].text.isNullOrBlank()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this style of assertions.

If the condition doesn't hold, it will just throw a timeout exception, regardless of the failure mode. I would want to distinguish between an unexpected response (e.g. 3 messages instead of 2), and a complete lack of response.

Moreover, if I understand the documentation correctly, this code will wait for 15 seconds even if the response arrives immediately.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover, if I understand the documentation correctly, this code will wait for 15 seconds even if the response arrives immediately.

This is not true. atMost waits at most the given time. Having the recordings ready the response arrives in <1s.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, but I still think it would be nice to distinguish between different failure modes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@odisseus
Copy link
Contributor

There are some minor style issues, otherwise looks good.

@mkondratek mkondratek force-pushed the mkondratek/it/context-files branch 2 times, most recently from 2510fe9 to 8100231 Compare July 31, 2024 07:28
@mkondratek mkondratek enabled auto-merge (squash) July 31, 2024 07:28
@mkondratek mkondratek mentioned this pull request Aug 6, 2024
mkondratek added a commit that referenced this pull request Aug 6, 2024
## Test plan
1. #1930 passing (so we are sure the fix to the enhanced context works)
@mkondratek mkondratek force-pushed the mkondratek/it/context-files branch 2 times, most recently from 1840ade to e9f6b27 Compare August 8, 2024 11:58
@mkondratek mkondratek merged commit b4672ed into main Aug 9, 2024
6 of 7 checks passed
@mkondratek mkondratek deleted the mkondratek/it/context-files branch August 9, 2024 13:02
mkondratek added a commit that referenced this pull request Aug 10, 2024
mkondratek added a commit that referenced this pull request Aug 10, 2024
Reverts #1930

Changes not ready yet.

## Test plan 
- Green CI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants